import request from '../utils/request';

/**
 * 设置相关API
 */
const settingApi = {


  /**
   * 获取个人信息 (别名)
   * @returns {Promise} - 个人信息结果
   */
  getPersonalInfo: async () => {
    try {
      const response = await request.get('/admin/settings/personal');
      return response;
    } catch (error) {
      console.error('获取个人信息失败:', error);
      throw error;
    }
  },



  /**
   * 更新个人信息 (别名)
   * @param {Object} personalInfo - 个人信息数据
   * @returns {Promise} - 更新结果
   */
  updatePersonalInfo: async (personalInfo) => {
    try {
      const response = await request.put('/admin/settings/personal', personalInfo);
      return response;
    } catch (error) {
      console.error('更新个人信息失败:', error);
      throw error;
    }
  },

  /**
   * 上传头像
   * @param {FormData} formData - 包含头像文件的FormData
   * @returns {Promise} - 上传结果
   */
  uploadAvatar: async (formData) => {
    try {
      const response = await request.post('/admin/settings/avatar', formData, {
        headers: {
          'Content-Type': 'multipart/form-data'
        }
      });
      return response;
    } catch (error) {
      console.error('上传头像失败:', error);
      throw error;
    }
  },
  

  
  /**
   * 获取系统配置
   * @returns {Promise} - 系统配置结果
   */
  getSystemConfig: async () => {
    try {
      const response = await request.get('/admin/settings/system');
      return response;
    } catch (error) {
      console.error('获取系统配置失败:', error);
      throw error;
    }
  },
  
  /**
   * 更新系统配置
   * @param {Object} config - 系统配置数据
   * @returns {Promise} - 更新结果
   */
  updateSystemConfig: async (config) => {
    try {
      const response = await request.put('/admin/settings/system', config);
      return response;
    } catch (error) {
      console.error('更新系统配置失败:', error);
      throw error;
    }
  },
  
  /**
   * 获取仪表盘统计信息
   * @returns {Promise} - 统计信息结果
   */
  getDashboardStats: async () => {
    try {
      const response = await request.get('/admin/dashboard/stats');
      return response;
    } catch (error) {
      console.error('获取仪表盘统计信息失败:', error);
      throw error;
    }
  },
  

};

export default settingApi;
export { settingApi };